<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/fontawesome.min.css" integrity="sha512-xX2rYBFJSj86W54Fyv1de80DWBq7zYLn2z0I9bIhQG+rxIF6XVJUpdGnsNHWRa6AvP89vtFupEPDP8eZAtu9qA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    --><link rel="stylesheet" href="./style.css" />
    <title>Login/Signup page</title>
  </head>
  <body>
    <h2>Sign in/ Sign up</h2>
    <div class="container" id="container">
      <div class="form-container sign-up-container">
        <form action="/regist" METHOD="post">
          <input type="text" name="username"></input>
          <input type="text" name="password"></input>
          <button>注册</button>
        </form>
      </div>
      <div class="form-container sign-in-container">
        <form action="/login" method="post">
          <h1>Sign in</h1>
          <input type="text" name="username" />
          <input type="password" name="password" />
          <button onclick="fun()">登录</button>
        </form>
      </div>
      <div class="overlay-container">
        <div class="overlay">
          <div class="overlay-panel overlay-left">
            <h1>Welcome Back!</h1>
            <p>
              To keep connected with us please login with your personal info
            </p>
            <button class="ghost" id="signIn">Sign In</button>
          </div>
          <div class="overlay-panel overlay-right">
            <h1>你好!</h1>
            <p>加入快乐的聊天吧！</p>
            <button class="ghost" id="signUp">注册</button>
          </div>
        </div>
      </div>
    </div>

    <script src="./script.js"></script>
    <script>
      //定义方法
      $(function () {
        $("#btn").click(function () {
          //获取username文本输入框的值
          let username = document.getElementById("username").value;
          let password = document.getElementById("password").value;
          //发送ajax请求
          $.ajax({
            url: "loginAjaxServlet",
            // data: {"username": username, "password": password},
            //序列化表单数据，根据input的name属性和value属性进行序列化，key(name):value(value),序列化之后自动变成json
            data:$("#myform").serialize(),
            dataType: "JSON",
            type: "POST",
            //返回的数据dataJSON格式
            success: function (data) {
              //具体操作
              if (data.code == 0) {
                window.location.href = "showUser.html"
              } else {
                alert(data.msg)
              }
            }
          });
        });
      });
    </script>
  </body>
</html>
